package com.itheima.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.PmsProductFullReductionMapper;
import com.itheima.pojo.PmsProductFullReduction;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductFullReductionImpl implements PmsProductFullReductionApi {

    @Autowired
    private PmsProductFullReductionMapper mapper;

    /**
     *商品添加
     */
    @Override
    public void save(List<PmsProductFullReduction> productFullReductionList, Long productId) {
        for (PmsProductFullReduction pmsProductFullReduction : productFullReductionList) {
            pmsProductFullReduction.setProductId(productId);
            mapper.insert(pmsProductFullReduction);
        }
    }

    /**
     *根据商品id获取商品编辑信息
     */
    @Override
    public List<PmsProductFullReduction> updateInfo(Integer productId) {
        LambdaQueryWrapper<PmsProductFullReduction> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsProductFullReduction::getProductId,productId);
        List<PmsProductFullReduction> pmsProductFullReductions = mapper.selectList(lqw);
        return pmsProductFullReductions;
    }

    /**
     *更新商品
     */
    @Override
    public void updateProduct(List<PmsProductFullReduction> productFullReductionList, Long productId) {
        for (PmsProductFullReduction pmsProductFullReduction : productFullReductionList) {
            pmsProductFullReduction.setProductId(productId);
            mapper.updateById(pmsProductFullReduction);
        }
    }

}
